package TrackModel;

/**
 * @author Jordan
 *Sub-Class of Block that adds additional functionality for a Crossing Block
 */
public class CrossingBlock extends Block 
{
	
	private boolean crossingState;
	
	/**Constructor for a Crossing Block object. Initializes a railroad crossing to "false", meaning it is not active
	 * @param theBlock - The String array containing the attributes that make up this object
	 */
	public CrossingBlock(String[] theBlock)
	{
		super(theBlock);
		crossingState = false;
	}
	
	/**
	 * @return Returns the new state of the crossing after it has been toggled
	 */
	public boolean toggleCrossing()
	{
		crossingState = !crossingState;
		return crossingState;
	}

	/* (non-Javadoc)
	 * @see TrackModel.Block#toString()
	 * Returns a String representation of a Crossing Block object
	 */
	public String toString()
	{
		StringBuilder other = new StringBuilder();
		if (isUnderground)
			other.append("Underground ");
		other.append("Rail Road Crossing is ");
		if (crossingState)
			other.append("active\n");
		else
			other.append("inactive\n");
		if (connections.length == 1)
			return "Block ID: "+blockID+"\tLength: "+length+"\tGrade: "+grade+"\tSpeed Limit: "+speedLimit+"\nElevation: "+elevation+"\t"
					+ "Connected to Block: "+connections[0]+"\nOther information: "+other.toString();
		else
			return "Block ID: "+blockID+"\tLength: "+length+"\tGrade: "+grade+"\tSpeed Limit: "+speedLimit+"\nElevation: "+elevation+"\t"
					+ "Connected to Blocks: "+connections[0]+", "+connections[1]+"\nOther information: "+other.toString();
	}
}